package com.briup.web;

import com.briup.pojo.Address;
import com.briup.pojo.Customer;
import com.briup.service.IAddressService;
import com.briup.serviceImp.AddressserviceImp;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;


public class FindAddressServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        HttpSession session = request.getSession();
        Customer customer = (Customer) session.getAttribute("login");
        if (customer==null){
            request.getRequestDispatcher("/login.jsp");
        }
        Integer id = customer.getId();
        IAddressService addressserviceImp = new AddressserviceImp();
        List<Address> addresses = addressserviceImp.findByCustomer(id);
        session.setAttribute("address",addresses);
        response.sendRedirect("./user/confirm.jsp");
    }
}
